<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script type="text/javascript" src="./qwebchannel.js"></script>
        <script type="text/javascript">
            //BEGIN SETUP
            window.onload = function() {

                  
                var baseUrl = "ws://localhost:12345";
                var socket = new WebSocket(baseUrl);
                socket.onclose = function() {
                    console.error("web channel closed");
                };

                socket.onerror = function(error) {
                    console.error("web channel error: " + error);
                };
                
                socket.onopen = function() {
                    new QWebChannel(socket, function(channel) {
                        // make core object accessible globally
                        window.core = channel.objects.core;
                        core.sendText("22222222");

                        document.getElementById("btn1").onclick = function() {
                            core.receiveText("hello world!");
                        }
                        
                        window.core.sendText1.connect(function(message) {
                            console.log("qt: " + message);
                        });

                        core.receiveText("Client connected, ready to send/receive messages!");
                    });
                }
            }
            //END SETUP
        </script>
    </head>
    <body>
        <button id="btn1">发送</button>
    </body>
</html>
